home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Views / Sources / UKeySelectionBehavior.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  4.4 KB  |  127 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // UKeySelectionBehavior.cp 
  3. // Copyright © 1985-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __UKEYSELECTIONBEHAVIOR__
  7. #include "UKeySelectionBehavior.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UEVENT__
  13. #include "UEvent.h"
  14. #endif
  15.  
  16. #ifndef __UMACAPPUTILITIES__
  17. #include "UMacAppUtilities.h"
  18. #endif
  19.  
  20. // Toolbox
  21.  
  22. #ifndef __LOWMEM__
  23. #include <LowMem.h>
  24. #endif
  25.  
  26.  
  27. //========================================================================================
  28. // CLASS TKeySelectionBehavior
  29. //========================================================================================
  30. #undef Inherited
  31. #define Inherited TBehavior
  32.  
  33. #pragma segment MAOpen
  34. MA_DEFINE_CLASS_M1(TKeySelectionBehavior, Inherited);
  35.  
  36. //----------------------------------------------------------------------------------------
  37. // TKeySelectionBehavior constructor
  38. //----------------------------------------------------------------------------------------
  39. #pragma segment MAOpen
  40.  
  41. TKeySelectionBehavior::TKeySelectionBehavior() :
  42.     fLastKeyUpTime(0)
  43. {
  44.     // A note on LMGetKeyThresh: the key repeat rate typically ranges
  45.     // from 12 ticks (short) to 40 ticks (long).  However, if key repeat
  46.     // is turned off, LMGetKeyThresh returns SHRT_MAX.  To prevent an
  47.     // fTimeOutInterval that high, we bound it at 255 ticks (about 4 seconds).
  48.     fTimeOutInterval = Min(::LMGetKeyThresh(),255);
  49. } // TKeySelectionBehavior::TKeySelectionBehavior
  50.  
  51. //----------------------------------------------------------------------------------------
  52. // TKeySelectionBehavior destructor
  53. //----------------------------------------------------------------------------------------
  54. #pragma segment MADestructorRes
  55.  
  56. TKeySelectionBehavior::~TKeySelectionBehavior()
  57. {
  58. }
  59.  
  60. //----------------------------------------------------------------------------------------
  61. // TKeySelectionBehavior::IKeySelectionBehavior: 
  62. //----------------------------------------------------------------------------------------
  63. #pragma segment MAOpen
  64.  
  65. void TKeySelectionBehavior::IKeySelectionBehavior(IDType itsIdentifier)
  66. {
  67.     this->IBehavior(itsIdentifier);
  68. } // TKeySelectionBehavior::IKeySelectionBehavior 
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // TKeySelectionBehavior::DoKeyEvent: 
  72. //----------------------------------------------------------------------------------------
  73. #pragma segment MARes
  74.  
  75. void TKeySelectionBehavior::DoKeyEvent(TToolboxEvent* event)
  76. {
  77.     if (event->IsOptionKeyPressed() || event->IsControlKeyPressed() || event->fText < chSpace)
  78.         Inherited::DoKeyEvent(event);
  79.     else
  80.     {
  81.         if (event->fEventRecord.when - fLastKeyUpTime >= fTimeOutInterval)
  82.             fKeySequence.Empty();
  83.         fKeySequence += event->fText;
  84.         this->DoKeySelection(fKeySequence);
  85.         fLastKeyUpTime = event->fEventRecord.when;
  86.     }
  87. } // TKeySelectionBehavior::DoKeyEvent 
  88.  
  89. //----------------------------------------------------------------------------------------
  90. // TKeySelectionBehavior::DoKeySelection: 
  91. //----------------------------------------------------------------------------------------
  92. #pragma segment MARes
  93.  
  94. void TKeySelectionBehavior::DoKeySelection(const CStr255& keySequence)
  95. {
  96.     if (fOwner)
  97.         fOwner->DoKeySelection(keySequence);
  98. } // TKeySelectionBehavior::DoKeySelection 
  99.  
  100. //----------------------------------------------------------------------------------------
  101. // TKeySelectionBehavior::DoKeyUp: 
  102. //----------------------------------------------------------------------------------------
  103. #pragma segment MARes
  104.  
  105. void TKeySelectionBehavior::DoKeyUp(TToolboxEvent* event)
  106. {
  107.     if (event->IsOptionKeyPressed() || event->IsControlKeyPressed() || event->fText < chSpace)
  108.         Inherited::DoKeyUp(event);
  109.     else
  110.         fLastKeyUpTime = event->fEventRecord.when;
  111. } // TKeySelectionBehavior::DoKeyUp 
  112.  
  113. //----------------------------------------------------------------------------------------
  114. // TKeySelectionBehavior::SetTimeOutInterval: 
  115. //----------------------------------------------------------------------------------------
  116. #pragma segment MAOpen
  117.  
  118. void TKeySelectionBehavior::SetTimeOutInterval(long timeOutInterval)
  119. {
  120.     fTimeOutInterval = timeOutInterval;
  121. } // TKeySelectionBehavior::SetTimeOutInterval 
  122.  
  123. //----------------------------------------------------------------------------------------
  124. // End of UKeySelectionBehavior.cp
  125.  
  126. #pragma segment Inline
  127.